/// <reference path="../../../../layuimini-master/js/lay-module/layuimini/minimenu.js" />
/**
 * date:2020/02/27
 * author:Mr.Chung
 * version:2.0
 * description:layuimini 菜单框架扩展
 */
layui.define(["element", "laytpl", "jquery"], function (exports) {
    var element = layui.element,
        $ = layui.$,
        laytpl = layui.laytpl,
        layer = layui.layer;


    let {
        //QD
        GetWebApiInfo,
        GetFormDataApiInfo,
        GetFormDataCondition,
        QDFitlerToEj2,
        Ej2ToQDFilter,
        QDFilterToEj2Rule,
        Ej2RuleToQDFilter,
        Ej2PredicateToEj2Rule,
        GetFormDataOrder,
        GetRequestTableObj,
        SetChildTableFilterValue,
        SetTableFilterValue,
        GetDataManagerObj,
        GetDataManagerByDataTable,
        GetTableRequestComplete,
        GetDataByDataTable,
        ExecRequest,
        Adaptor,
        //QC
        SysLogin,
        LoginOut,
        RecordMyUserInfo,
        isEmptyObject,
        StringTrim,
        GetNewGUID,
        GetQueryString,
        ReturnPortalCenter,
        GetFormFilePath,
        GridAutoSize,
        EditScreenShotPage,
        //comm
        CheckboxList,
        ALink,
        QYCardView,
        QYIconSelector,
        BindFormCtrl,
        LayoutGroupBind,
        CascadingChildCtrl,
        QYCtrlBind,
        UploadPopupExt,
        UploadSetCustomPath,
        ToSelectFilesAction,
        SysUploadFileSelected,
        FileUpload,
        FileDelete,
        FileDownload,
        CreateFolder,
        FileCopy,
        FileMove,
        FileRename,
        FileView,
        //pagebind
        FormInit,
        GetFormDataApiUrl,
        GetGridColumnEditParam,
        SysSelectDataBind,
        GridBind,
        CtrlBind,
        LocaDataBind,
        SetFromDataCurrentRow,
        SetFromDataCurrentRowBayKeyValue,
        SetFromDataSelectRow,
        SetFromDataSelectRowByKeyValue,
        GetFormChildDataObj,
        SaveAllData,
        BatchSave,
        SysAppend,
        ReplaceDisplayClass,
        GetFormFunData,
        GetUserShowFun,
        GetUserEditFun,
        SetGridFun,
        GridRowSelecting,
        GridQueryCellInfo,
        GridBeforeBatchAdd,
        GridBeginEdit,
        ValidateData,
        CreateSysGridToolbarTemp,
        GridImportFile,
        GetGridImportParam,
        ShowTempEditPopup,
        HideTempEditPopup,
        SetTreeViewSelectNode,
        StartFlow,
        RevokeFlow,
        ReturnFlow,
        EndFlow,
        AddFlowReceiveUser,
        GetFlowCandidate,
        GetDataSource,
        OpenIconLibrary,
        //ctrl
        PanelExt,
        GridViewExt,
        FormLayoutExt,
        QYLabel,
        QYSpinEdit,
        QYColorEdit,
        QYPopup,
        QYTabGroup,
        QYBadge,
        QYCustomFilter,
        QYFileView,
        QYFileManager,
        replaceIllegalCharactersWithFullWidth,
        BtnTextBoxColumnTempExt,
        CheckBoxListTempExt,
        ColorEditColumnTempExt,
        SpinEditColumnTempExt,
        DropDownTreeColumnTempExt,
        HyperLinkColumnTempExt,
        ImageColumnTempExt,
        TextBoxColumnTempExt,
        TokenBoxColumnTempExt,
        ComboBoxColumnTempExt,
        SetFilterRowData,
        DepUserSelectPopupExt,
        QueryBuilderExt,
        ValueFunPopupExt,
        QYCreateCtrlEle,
        QYCreateGroupEle,
        QYSetCaptionEle,
        QYDiagram,
        FlowExecObj,
        SubmitNode,
    } = {};

    var miniMenu = {

        /**
         * 菜单初始化
         * @param options.menuList   菜单数据信息
         * @param options.multiModule 是否开启多模块
         * @param options.menuChildOpen 是否展开子菜单
         */
        render: function (options) {

            ({
                //QD
                GetWebApiInfo,
                GetFormDataApiInfo,
                GetFormDataCondition,
                QDFitlerToEj2,
                Ej2ToQDFilter,
                QDFilterToEj2Rule,
                Ej2RuleToQDFilter,
                Ej2PredicateToEj2Rule,
                GetFormDataOrder,
                GetRequestTableObj,
                SetChildTableFilterValue,
                SetTableFilterValue,
                GetDataManagerObj,
                GetDataManagerByDataTable,
                GetTableRequestComplete,
                GetDataByDataTable,
                ExecRequest,
                Adaptor,
                //QC
                SysLogin,
                LoginOut,
                RecordMyUserInfo,
                isEmptyObject,
                StringTrim,
                GetNewGUID,
                GetQueryString,
                ReturnPortalCenter,
                GetFormFilePath,
                GridAutoSize,
                EditScreenShotPage,
                //comm
                CheckboxList,
                ALink,
                QYCardView,
                QYIconSelector,
                BindFormCtrl,
                LayoutGroupBind,
                CascadingChildCtrl,
                QYCtrlBind,
                UploadPopupExt,
                UploadSetCustomPath,
                ToSelectFilesAction,
                SysUploadFileSelected,
                FileUpload,
                FileDelete,
                FileDownload,
                CreateFolder,
                FileCopy,
                FileMove,
                FileRename,
                FileView,
                //pagebind
                FormInit,
                GetFormDataApiUrl,
                GetGridColumnEditParam,
                SysSelectDataBind,
                GridBind,
                CtrlBind,
                LocaDataBind,
                SetFromDataCurrentRow,
                SetFromDataCurrentRowBayKeyValue,
                SetFromDataSelectRow,
                SetFromDataSelectRowByKeyValue,
                GetFormChildDataObj,
                SaveAllData,
                BatchSave,
                SysAppend,
                ReplaceDisplayClass,
                GetFormFunData,
                GetUserShowFun,
                GetUserEditFun,
                SetGridFun,
                GridRowSelecting,
                GridQueryCellInfo,
                GridBeforeBatchAdd,
                GridBeginEdit,
                ValidateData,
                CreateSysGridToolbarTemp,
                GridImportFile,
                GetGridImportParam,
                ShowTempEditPopup,
                HideTempEditPopup,
                SetTreeViewSelectNode,
                StartFlow,
                RevokeFlow,
                ReturnFlow,
                EndFlow,
                AddFlowReceiveUser,
                GetFlowCandidate,
                GetDataSource,
                OpenIconLibrary,
                //ctrl
                PanelExt,
                GridViewExt,
                FormLayoutExt,
                QYLabel,
                QYSpinEdit,
                QYColorEdit,
                QYPopup,
                QYTabGroup,
                QYBadge,
                QYCustomFilter,
                QYFileView,
                QYFileManager,
                replaceIllegalCharactersWithFullWidth,
                BtnTextBoxColumnTempExt,
                CheckBoxListTempExt,
                ColorEditColumnTempExt,
                SpinEditColumnTempExt,
                DropDownTreeColumnTempExt,
                HyperLinkColumnTempExt,
                ImageColumnTempExt,
                TextBoxColumnTempExt,
                TokenBoxColumnTempExt,
                ComboBoxColumnTempExt,
                SetFilterRowData,
                DepUserSelectPopupExt,
                QueryBuilderExt,
                ValueFunPopupExt,
                QYCreateCtrlEle,
                QYCreateGroupEle,
                QYSetCaptionEle,
                QYDiagram,
                FlowExecObj,
                SubmitNode,
            } = options.QyCtrl);

            options.menuList = options.menuList || [];
            options.leftMenuList = options.leftMenuList || [];
            options.dataMenuList = options.dataMenuList || [];
            options.relationInfo = options.relationInfo || [];
            options.multiModule = options.multiModule || false;
            options.menuChildOpen = options.menuChildOpen || false;
            options.firstItemsLocation = options.firstItemsLocation || "Top";
            options.logoInfo = options.logoInfo;
            if (options.multiModule) {
                miniMenu.renderMultiModule(options.menuList, options.leftMenuList, options.firstItemsLocation, options.logoInfo, options.menuChildOpen);
            } else {
                miniMenu.renderSingleModule(options.menuList, options.menuChildOpen);
            }

            if (options.dataMenuList && options.dataMenuList.length > 0) {
                miniMenu.renderDataMenu(options.dataMenuList, false);
            }

            element.init();

            if (options.firstItemsLocation === "Top") {
                miniMenu.setLeftMenu();
            }

            layui.miniAdmin.renderFirstPage();

            miniMenu.listen();
        },



        /**
         * 单模块
         * @param menuList 菜单数据
         * @param menuChildOpen 是否默认展开
         */
        renderSingleModule: function (menuList, menuChildOpen) {
            menuList = menuList || [];
            var leftMenuHtml = '',
                childOpenClass = '',
                leftMenuCheckDefault = 'layui-this';
            var me = this;
            if (menuChildOpen) childOpenClass = ' layui-nav-itemed';
            leftMenuHtml = this.renderLeftMenu(menuList, { childOpenClass: childOpenClass });
            $('.layui-layout-body').addClass('layuimini-single-module'); //单模块标识
            $('.layuimini-header-menu').remove();
            $('.layuimini-menu-left').html(leftMenuHtml);

        },


        //'<li {{#if( d.menu){ }}  data-menu="{{d.menu}}" {{#}}} class="layui-nav-item menu-li {{d.childOpenClass}} {{d.className}}"> <a {{#if( d.href){ }} layuimini-href="{{d.href}}" {{#}}} {{#if( d.target){ }}  target="{{d.target}}" {{#}}}  {{#if( d.id){ }}  id="{{d.id}}" {{#}}} href="javascript:;">{{#if( d.icon){ }}  <i class="{{d.icon}}"></i> {{#}}} <span class="layui-left-nav">{{d.title}}</span></a>  {{# if(d.children){}} {{-d.children}} {{#}}} </li>'

        //'<dd class="menu-dd {{d.childOpenClass}} {{ d.className }}"> <a href="javascript:;"  {{#if( d.menu){ }}  data-menu="{{d.menu}}" {{#}}} {{#if( d.id){ }}  id="{{d.id}}" {{#}}} {{#if(( !d.child || !d.child.length ) && d.href){ }} layuimini-href="{{d.href}}" {{#}}} {{#if( d.target){ }}  target="{{d.target}}" {{#}}}> {{#if( d.icon){ }}  <i class="{{d.icon}}"></i> {{#}}} <span class="layui-left-nav"> {{d.title}}</span></a> {{# if(d.children){}} {{-d.children}} {{#}}}</dd>'
        /**
         * 渲染一级菜单
         */
        compileMenu: function (menu, isSub) {
            menu.icon = this.setIconClass(menu.icon);
            /*            var menuHtml = '<li {{#if( d.menu){ }}  data-menu="{{d.menu}}" {{#}}} class="layui-nav-item menu-li {{d.childOpenClass}} {{d.className}}"> <a layuimini-href="{{d.href}}" {{#if( d.target){ }}  target="{{d.target}}" {{#}}}  {{#if( d.id){ }}  id="{{d.id}}" {{#}}} href="javascript:;">{{#if( d.icon){ }}  <i class="{{d.icon}}"></i> {{#}}} <span class="layui-left-nav">{{d.title}}</span></a>  {{# if(d.children){}} {{-d.children}} {{#}}} </li>';*/
            if (isSub) {
                //menuHtml = '<dd class="menu-dd {{d.childOpenClass}} {{ d.className }}"> <a href="javascript:;"  {{#if( d.menu){ }}  data-menu="{{d.menu}}" {{#}}} {{#if( d.id){ }}  id="{{d.id}}" {{#}}} layuimini-href="{{d.href}}" {{#if( d.target){ }}  target="{{d.target}}" {{#}}}> {{#if( d.icon){ }}  <i class="{{d.icon}}"></i> {{#}}} <span class="layui-left-nav"> {{d.title}}</span></a> {{# if(d.children){}} {{-d.children}} {{#}}}</dd>'

                return `
                        <dd class="menu-dd ${menu.childOpenClass || ''} ${menu.className || ''}">
                          <a href="javascript:;"
                            ${menu.menu ? `data-menu="${menu.menu}"` : ''}
                            ${menu.id ? `id="${menu.id}"` : ''}
                            layuimini-href="${menu.href}"
                            ${menu.target ? `target="${menu.target}"` : ''}>
                            ${menu.icon ? `<i class="${menu.icon}"></i>` : ''}
                            <span class="layui-left-nav">${menu.title}</span>
                          </a>
                          ${menu.children ? menu.children : ''}
                        </dd>
                        `
            } else {
                return `
                        <li 
                          ${menu.menu ? `data-menu="${menu.menu}"` : ''} 
                          class="layui-nav-item menu-li ${menu.childOpenClass || ''} ${menu.className || ''}">
                          <a
                            layuimini-href="${menu.href}"
                            ${menu.target ? `target="${menu.target}"` : ''}
                            ${menu.id ? `id="${menu.id}"` : ''}
                            href="javascript:;"
                          >
                            ${menu.icon ? `<i class="${menu.icon}"></i>` : ''}
                            <span class="layui-left-nav">${menu.title}</span>
                          </a>
                          ${menu.children ? menu.children : ''}
                        </li>
                        `;
                //return laytpl(menuHtml).render(menu);
            }
        },
        compileMenuContainer: function (menu, isSub) {
            var wrapperHtml = '<ul class="layui-nav layui-nav-tree layui-left-nav-tree {{d.className}}" id="{{d.id}}">{{-d.children}}</ul>';
            if (isSub) {
                wrapperHtml = '<dl class="layui-nav-child ">{{-d.children}}</dl>';
            }
            if (!menu.children) {
                return "";
            }
            return laytpl(wrapperHtml).render(menu);
        },


        compileHeaderMenu: function (menus, isSub) {
            if (isSub) {
                if (!menus || menus.length == 0) return "";
                var childMenu = `<dl class="layui-nav-child">
                                ${menus.map(menu =>
                    `<dd">
                                        <a id="${menu.id} href="javascript:;" layuimini-href="${menu.NavigationUrl}">${menu.text}</a>
                                    </dd>`).join("")}
                                </dl>`;
                return childMenu;
            }
            else {
                var headerHtml = `<li data-menu="${menus.menu}"  class="layui-nav-item menu-li ${menus.childOpenClass} ${menus.className}"> 
                                    <a data-menu="${menus.menu}" layuimini-href="${menus.href}"  target="${menus.target}"  id="${menus.id}"  href="javascript:;">
                                        ${menus.icon ? `<i class="${this.setIconClass(menus.icon)}"></i>` : ""} 
                                        <span class="layui-left-nav">${menus.title}</span>
                                    </a>  ${menus.children ? `${menus.children}` : ""}
                                </li>`;

                return headerHtml;
            }
        },

        /**
         * 渲染数据目录项
         */
        compileDataMenu: function (menu, isSub) {
            menu.icon = this.setIconClass(menu.icon);
            var menuHtml = '<li class="layui-nav-item layuimini-setting {{d.childOpenClass}} {{d.className}}"  {{#if( d.id){ }}  id="{{d.id}}" {{#}}}> <a href="javascript:;">{{d.title}}</a>  {{# if(d.children){}} {{-d.children}} {{#}}} </li>';
            if (isSub) {
                menuHtml = '<dd class="{{ d.className }}"> <a href="javascript:;" id="{{d.id}}" layuimini-datamenu-href="{{d.pid}}" layuimini-datamenu-text="{{d.text}}" layuimini-datamenu-value="{{d.id}}" > {{#if( d.icon){ }}  <i class="{{d.icon}}"></i> {{#}}} <span> {{d.title}}</span></a> {{# if(d.children){}} {{-d.children}} {{#}}}</dd>'
            }
            return laytpl(menuHtml).render(menu);
        },
        compileDataMenuContainer: function (menu, isSub) {
            var wrapperHtml = '<ul class="layui-nav layui-nav-tree layui-left-nav-tree {{d.className}}" id="{{d.id}}">{{-d.children}}</ul>';
            if (isSub) {
                wrapperHtml = '<dl class="layui-nav-child layui-anim layui-anim-upbit">{{-d.children}}</dl>';
            }
            if (!menu.children) {
                return "";
            }
            return laytpl(wrapperHtml).render(menu);
        },

        each: function (list, callback) {
            var _list = [];
            for (var i = 0, length = list.length; i < length; i++) {
                _list[i] = callback(i, list[i]);
            }
            return _list;
        },
        //renderChildrenMenu: function (menuList, options) {
        //    var me = this;
        //    menuList = menuList || [];
        //    var html = this.each(menuList, function (idx, menu) {
        //        if (menu.child && menu.child.length) {
        //            menu.children = me.renderChildrenMenu(menu.child, { childOpenClass: options.childOpenClass || '' });
        //        }
        //        menu.className = "";
        //        menu.childOpenClass = options.childOpenClass || ''
        //        return me.compileMenu(menu, true)
        //    }).join("");
        //    return me.compileMenuContainer({ children: html }, true)
        //},
        //renderLeftMenu: function (leftMenus, options) {
        //    options = options || {};
        //    var me = this;
        //    var leftMenusHtml = me.each(leftMenus || [], function (idx, leftMenu) { // 左侧菜单遍历
        //        var children = me.renderChildrenMenu(leftMenu.child, { childOpenClass: options.childOpenClass });
        //        var leftMenuHtml = me.compileMenu({
        //            id: leftMenu.id,
        //            href: leftMenu.href,
        //            target: leftMenu.target,
        //            childOpenClass: options.childOpenClass,
        //            icon: leftMenu.icon,
        //            title: leftMenu.title,
        //            children: children,
        //            className: '',
        //        });
        //        return leftMenuHtml;
        //    }).join("");

        //    leftMenusHtml = me.compileMenuContainer({ id: options.parentMenuId, className: options.leftMenuCheckDefault, children: leftMenusHtml });
        //    return leftMenusHtml;
        //},        
        renderChildrenMenu: function (menuList, options) {
            var me = this;
            menuList = menuList || [];
            var html = this.each(menuList, function (idx, menu) {
                if (menu.items && menu.items.length) {
                    menu.children = me.renderChildrenMenu(menu.items, { childOpenClass: options.childOpenClass || '' });
                }
                menu.className = "";
                menu.childOpenClass = options.childOpenClass || ''
                return me.compileMenu({
                    id: menu.id,
                    href: menu.NavigationUrl || "",
                    target: menu.target,
                    childOpenClass: menu.childOpenClass,
                    icon: menu.iconCss,
                    title: menu.text,
                }, true)//(menu, true)
            }).join("");
            return me.compileMenuContainer({ children: html }, true)
        },
        renderLeftMenu: function (leftMenus, options) {
            options = options || {};
            var me = this;
            var leftMenusHtml = me.each(leftMenus || [], function (idx, leftMenu) { // 左侧菜单遍历
                var children = me.renderChildrenMenu(leftMenu.items, { childOpenClass: options.childOpenClass });
                var leftMenuHtml = me.compileMenu({
                    id: leftMenu.id,
                    href: leftMenu.NavigationUrl || "",
                    target: leftMenu.target,
                    childOpenClass: options.childOpenClass,
                    icon: leftMenu.iconCss,
                    title: leftMenu.text,
                    children: children,
                    className: '',
                });
                return leftMenuHtml;
            }).join("");

            leftMenusHtml = me.compileMenuContainer({ id: options.parentMenuId, className: options.leftMenuCheckDefault, children: leftMenusHtml });
            return leftMenusHtml;
        },

        renderDataMenuItems: function (itemsList, options) {
            var me = this;
            itemsList = itemsList || [];
            var html = this.each(itemsList, function (idx, dataItem) {
                dataItem.className = "";
                dataItem.childOpenClass = options.childOpenClass || '';
                dataItem.title = dataItem.text;
                dataItem.icon = dataItem.iconCss;
                return me.compileDataMenu(dataItem, true)
            }).join("");
            return me.compileDataMenuContainer({ children: html }, true)
        },

        renderDataMenu: function (dataMenus, options) {
            options = options || {};
            var me = this;
            var dataMenusHtml = me.each(dataMenus || [], function (idx, dataMenu) { // 左侧菜单遍历
                var children = me.renderDataMenuItems(dataMenu.items, { childOpenClass: options.childOpenClass });


                var initItemVal = GetQueryString(dataMenu.InitValParam);
                var TitleLocation = dataMenu.TitleLocation;
                var initItemSel = initItemVal && initItemVal != "" && initItemVal != "null" ? dataMenu.items.find(x => x.id == initItemVal) : dataMenu.items[0];
                var initText = TitleLocation == "right" ? `${initItemSel.text} ${dataMenu.text}` : `${dataMenu.text}：${initItemSel.text}`;

                layui.miniAdmin.dataMenuSelected.push({
                    dataMenuId: initItemSel.pid,
                    selectedValue: initItemSel.id,
                    selectedText: initItemSel.text
                });

                var leftMenuHtml = me.compileDataMenu({
                    //href: dataMenu.href,
                    //target: dataMenu.target,
                    id: dataMenu.id,
                    childOpenClass: options.childOpenClass,
                    icon: dataMenu.iconCss,
                    title: initText,
                    children: children,
                    className: '',
                });
                return leftMenuHtml;
            }).join("");

            $('.layui-layout-right').html(dataMenusHtml);

        },

        ///**
        // * 多模块
        // * @param menuList 菜单数据
        // * @param menuChildOpen 是否默认展开
        // */
        //renderMultiModule: function (menuList, menuChildOpen) {
        //    menuList = menuList || [];
        //    var me = this;
        //    var headerMenuHtml = '',
        //        headerMobileMenuHtml = '',
        //        leftMenuHtml = '',
        //        leftMenuCheckDefault = 'layui-this',
        //        childOpenClass = '',
        //        headerMenuCheckDefault = 'layui-this';

        //    if (menuChildOpen) childOpenClass = ' layui-nav-itemed';
        //    var headerMenuHtml = this.each(menuList, function (index, val) { //顶部菜单渲染
        //        var menu = val.id;// 'multi_module_' + index;
        //        var id = menu + "HeaderId";
        //        var topMenuItemHtml = "";
        //        topMenuItemHtml = me.compileMenu({
        //            className: headerMenuCheckDefault,
        //            menu: menu,
        //            id: id,
        //            title: val.title,
        //            href: "",
        //            target: "",
        //            children: ""
        //        });
        //        leftMenuHtml += me.renderLeftMenu(val.child, {
        //            parentMenuId: menu,
        //            childOpenClass: childOpenClass,
        //            leftMenuCheckDefault: leftMenuCheckDefault
        //        });
        //        headerMobileMenuHtml += me.compileMenu({ id: id, menu: menu, id: id, icon: val.icon, title: val.title, }, true);
        //        headerMenuCheckDefault = "";
        //        leftMenuCheckDefault = "layui-hide";
        //        return topMenuItemHtml;
        //    }).join("");
        //    $('.layui-layout-body').addClass('layuimini-multi-module'); //多模块标识
        //    $('.layuimini-menu-header-pc').html(headerMenuHtml); //电脑
        //    $('.layuimini-menu-left').html(leftMenuHtml);
        //    $('.layuimini-menu-header-mobile').html(headerMobileMenuHtml); //手机
        //},
        /**
         * 多模块
         * @param menuList 头部菜单数据
         * @param leftMenuList 左侧菜单数据
         * @param firstItemsLocation 第一层导航初始位置
         * @param logoInfo 应用信息
         * @param menuChildOpen 是否默认展开
         */
        renderMultiModule: function (menuList, leftMenuList, firstItemsLocation, logoInfo, menuChildOpen) {
            menuList = menuList || [];
            var me = this;
            var headerMenuHtml = '',
                headerMobileMenuHtml = '',
                leftMenuHtml = '',
                leftMenuCheckDefault = 'layui-this',
                childOpenClass = '',
                headerMenuCheckDefault = 'layui-this';

            if (menuChildOpen) childOpenClass = ' layui-nav-itemed';
            //判断从顶部或左侧开始加载导航项
            if (firstItemsLocation === "Top") {
                var headerMenuHtml = this.each(menuList, function (index, val) { //顶部菜单渲染
                    var menu = val.id;// 'multi_module_' + index;
                    var id = menu + "HeaderId";
                    var topMenuItemHtml = "";
                    var childTopHtml = me.compileHeaderMenu(val.items, true);
                    topMenuItemHtml = me.compileHeaderMenu({
                        className: headerMenuCheckDefault,
                        menu: menu,
                        id: id,
                        title: val.text,
                        href: val.NavigationUrl || "",
                        target: "",
                        icon: val.iconCss,
                        children: childTopHtml
                    });

                    var childLeftMenus = leftMenuList.filter(x => x.pid == menu);
                    leftMenuHtml += me.renderLeftMenu(childLeftMenus, {
                        parentMenuId: menu,
                        childOpenClass: childOpenClass,
                        leftMenuCheckDefault: leftMenuCheckDefault
                    });
                    headerMobileMenuHtml += me.compileMenu({ id: id, menu: menu, icon: val.iconCss, title: val.text, }, true);
                    headerMenuCheckDefault = "";
                    leftMenuCheckDefault = "layui-hide";
                    return topMenuItemHtml;
                }).join("");
            } else {
                childOpenClass = 'layui-this';
                this.margerLeftMenuListData(menuList, leftMenuList);

                let menu = menuList[0].pid;
                let id = menu + "HeaderId";
                headerMenuHtml = me.compileHeaderMenu({
                    className: headerMenuCheckDefault,
                    menu: menu,
                    id: id,
                    title: logoInfo.title,
                    href: "",
                    target: "",
                    icon: logoInfo.iconCss,
                    children: ""
                });

                leftMenuHtml = me.renderLeftMenu(menuList, {
                    parentMenuId: menu,
                    childOpenClass: childOpenClass,
                    leftMenuCheckDefault: leftMenuCheckDefault
                });

            }
            $('.layui-layout-body').addClass('layuimini-multi-module'); //多模块标识
            $('.layuimini-menu-header-pc').html(headerMenuHtml); //电脑
            $('.layuimini-menu-left').html(leftMenuHtml);
            $('.layuimini-menu-header-mobile').html(headerMobileMenuHtml); //手机
        },

        margerLeftMenuListData: function (topList, leftList, curItem) {
            if (!curItem) {
                topList.forEach((pItem) => {
                    if (!pItem.items || pItem.items.length == 0)
                        pItem.items = leftList.filter(x => x.pid == pItem.id);

                    pItem.items.forEach((childItem) => {
                        this.margerLeftMenuListData(topList, leftList, childItem);
                    });
                });
            } else {
                if (!curItem.items || curItem.items.length == 0)
                    curItem.items = leftList.filter(x => x.pid == curItem.id);

                curItem.items.forEach((childItem) => {
                    this.margerLeftMenuListData(topList, leftList, childItem);
                });
            }
        },

        setIconClass: function (className) {
            if (className) {
                if (className.indexOf("layui-icon") != -1) {
                    return "fa layui-icon " + className;
                } else if (className.indexOf("e-icons") != -1) {
                    return className;
                } else {
                    return "fa " + className;
                }
            } else {
                return "fa layui-icon ";
            }
        },


        setLeftMenu: function (menuId) {
            if (document.getElementById("layuiminiHomeTabId")) {
                return document.getElementById(menuId) ? true : false;
            }

            if (!menuId) {
                var headerSel = document.querySelector(".layuimini-header-menu .layui-nav-item.layui-this");
                menuId = headerSel.getAttribute("data-menu");

            }
            var leftDiv = document.querySelector(".layui-side.layui-bg-black.layuimini-menu-left");
            var bodyDiv = document.querySelector(".layui-body");
            if (!document.getElementById(menuId)) {
                leftDiv.classList.add("layui-hide");
                bodyDiv.style.left = "0px";
            } else {
                leftDiv.classList.remove("layui-hide");
                bodyDiv.style.left = leftDiv.style.width;
            }

            return true;
        },

        /**
         * 监听
         */
        listen: function () {

            /**
             * 菜单模块切换
             */
            $('body').on('click', '[data-menu]', function (args) {
                var loading = layer.load(0, { shade: false, time: 2 * 1000 });
                var menuId = $(this).attr('data-menu');

                if (args.ctrlKey) {
                    var selMenu = layui.miniAdmin.headerMenus.find(x => x.id == menuId);
                    var sysId = selMenu.SysId;
                    // var sysId = "";
                    // if (selMenu) {
                    //     sysId = selMenu.SysId;
                    // } else {
                    //     sysId = layui.miniAdmin.leftMenus.find(x => x.id == menuId).SysId;
                    // }
                    var funSetUrl = "DataCenter/AppManagement/content/功能设置.html?flownodeid=&navid=" + menuId + "&sysid=" + sysId;
                    //funSetUrl = GetEntFullPath(funSetUrl);
                    DLG.Show(1440, 760, funSetUrl, "功能设置", function () { window.location.reload(); });
                    layer.close(loading);
                    return;
                }

                var hasLeft = miniMenu.setLeftMenu(menuId);
                if (!hasLeft) {
                    layer.close(loading);
                    return false;
                }


                // header//如果存在左侧菜单，会移除顶部菜单选中
                //$(".layuimini-header-menu .layui-nav-item.layui-this").removeClass('layui-this');
                //$(this).addClass('layui-this');
                // left
                $(".layuimini-menu-left .layui-nav.layui-nav-tree.layui-this").addClass('layui-hide');
                $(".layuimini-menu-left .layui-nav.layui-nav-tree.layui-this.layui-hide").removeClass('layui-this');

                $("#" + menuId).removeClass('layui-hide');
                $("#" + menuId).addClass('layui-this');
                layer.close(loading);
            });

            /**
             * 菜单缩放
             */
            $('body').on('click', '.layuimini-site-mobile', function () {
                var loading = layer.load(0, { shade: false, time: 2 * 1000 });
                var isShow = $('.layuimini-tool [data-side-fold]').attr('data-side-fold') + "";
                if (isShow == "1") { // 缩放
                    $('.layuimini-tool [data-side-fold]').attr('data-side-fold', 0);
                    $('.layuimini-tool [data-side-fold]').attr('class', 'fa fa-indent');
                    $('.layui-layout-body').removeClass('layuimini-all');
                    $('.layui-layout-body').addClass('layuimini-mini');
                } else { // 正常
                    $('.layuimini-tool [data-side-fold]').attr('data-side-fold', 1);
                    $('.layuimini-tool [data-side-fold]').attr('class', 'fa fa-outdent');
                    $('.layui-layout-body').removeClass('layuimini-mini');
                    $('.layui-layout-body').addClass('layuimini-all');
                    layer.close(window.openTips);
                }
                element.init();
                layer.close(loading);
            });
            /**
             * 菜单缩放
             */
            $('body').on('click', '[data-side-fold]', function () {
                var loading = layer.load(0, { shade: false, time: 2 * 1000 });
                var isShow = $('.layuimini-tool [data-side-fold]').attr('data-side-fold') + "";
                if (isShow == "1") { // 缩放
                    $('.layuimini-tool [data-side-fold]').attr('data-side-fold', 0);
                    $('.layuimini-tool [data-side-fold]').attr('class', 'fa fa-indent');
                    $('.layui-layout-body').removeClass('layuimini-all');
                    $('.layui-layout-body').addClass('layuimini-mini');
                    // $(".menu-li").each(function (idx,el) {
                    //     $(el).addClass("hidden-sub-menu");
                    // });

                } else { // 正常
                    $('.layuimini-tool [data-side-fold]').attr('data-side-fold', 1);
                    $('.layuimini-tool [data-side-fold]').attr('class', 'fa fa-outdent');
                    $('.layui-layout-body').removeClass('layuimini-mini');
                    $('.layui-layout-body').addClass('layuimini-all');
                    // $(".menu-li").each(function (idx,el) {
                    //     $(el).removeClass("hidden-sub-menu");
                    // });
                    layer.close(window.openTips);
                }
                element.init();
                layer.close(loading);
            });

            /**
             * 手机端点开模块
             */
            $('body').on('click', '.layuimini-header-menu.layuimini-mobile-show dd', function () {
                var loading = layer.load(0, { shade: false, time: 2 * 1000 });
                var check = $('.layuimini-tool [data-side-fold]').attr('data-side-fold');
                if (check === "1") {
                    $('.layuimini-site-mobile').trigger("click");
                    element.init();
                }
                layer.close(loading);
            });
        },

    };


    exports("miniMenu", miniMenu);
});
